<template>
  <Modal v-model="visible" width="450" title="请进行审核" @on-visible-change="closeModal">
    <Form ref="form" :model="form" :rules="rules" :label-width="120">
      <FormItem label="客户来源渠道:">
        {{ data.channelName }}
      </FormItem>
      <FormItem label="渠道合作类型:">
        {{ data.cooperationTypeName }}
      </FormItem>
      <FormItem label="渠道费用:">
        <!-- {{ data.channelCostValue || '--' }}元 -->
        <Input v-model="data.channelCostValue" type="text" placeholder="请输入">
        <template #append>
          元
        </template>
        </Input>
      </FormItem>
      <FormItem label="审核结果:" prop="result">
        <Select v-model="form.result">
          <Option :value="1">通过</Option>
          <Option :value="0">不通过</Option>
        </Select>
      </FormItem>
      <FormItem label="审核备注:" v-if="form.result === 1">
        <Input v-model="form.rejectReason" :maxlength="300" show-word-limit :rows="4"
          type="textarea" placeholder="请输入" />
      </FormItem>
      <FormItem v-if="form.result === 0">
        <p slot="label" style="display: flex; justify-content: flex-end;">
          <span style="color: #ed4014; font-size: 20px; margin-right: 4px;">*</span>
          <label>驳回原因:</label>
        </p>
        <Input v-model="form.rejectReason" :maxlength="300" show-word-limit :rows="4"
          type="textarea" placeholder="请输入" />
      </FormItem>
    </Form>
    <div slot="footer">
      <Button type="text" @click="onClose">取消</Button>
      <Button type="primary" :loading="loading" @click="onConfirm">确定</Button>
    </div>
  </Modal>
</template>

<script>
  import auditMgr from '@/biz/flowApproval/riskAudit.js'

  export default {
    props: {
      data: Object,
      nodeType: Number
    },
    data() {
      return {
        visible: false,
        form: {
          result: '',
          rejectReason: ''
        },
        rules: {
          result: [
            { required: true, type: 'number', message: '请选择审核结果', trigger: 'blur' },
          ]
        },
        loading: false
      }
    },

    methods: {
      onConfirm() {
        this.$refs.form.validate((valid) => {
          if (valid) {
            if (this.form.result === 0 && !this.form.rejectReason) {
              this.$Message.error('请填写驳回原因')
              return
            }
            this.loading = true
            auditMgr.audit({
              orderReviewId: this.data.orderReviewId,
              nodeType: this.nodeType,
              channelCostValue: this.data.channelCostValue,
              result: this.form.result ? true : false,
              rejectReason: this.form.rejectReason
            }).then(() => {
              this.loading = false
              this.$Message.success(this.form.result ? '审核通过' : '审核已驳回')
              this.onClose()
              this.$emit('success')
            }).catch(() => {
              this.loading = false
            })
          }
        })
      },
      onClose() {
        this.visible = false
      },
      closeModal(res) {
        if (!res) {
          this.form = {
            result: '',
            rejectReason: ''
          }
          this.$refs.form.resetFields()
        }
      },
    },
  }
</script>

<style lang='scss' scoped>
</style>